function w = weightsCK(d)

       global n priorvar Cbar1 Cbar0 Vtilde1 Vtilde0 Sigma1 Sigma0
       
       weights=zeros(n,1);
       
       
       Ky1=Vtilde1(d==1, d==1) + diag(Sigma1(d==1));
       Ky0=Vtilde0(d==0, d==0) + diag(Sigma0(d==0));
       
       
       weights(logical(d),:) = Ky1 \ Cbar1(d==1)';
       weights(logical(1-d),:) = - Ky0 \ Cbar0(d==0)';
       
       
       w = weights;
            
return
